/*
 * ControlLayer.cpp
 *
 *  Created on: 2010-9-12
 *      Author: try
 */

#include "ControlLayer.h"
#include "WorkPage.h"
#include "WorkLayer.h"

using namespace Ed;
using namespace Thk;
namespace S{
  ControlLayer::ControlLayer(WorkPage* page, WorkLayer* workLayer): Layer(page)
  , workLayer(workLayer),
    toTopBtnLstner(this),
    toBottomBtnLstner(this),
    toUpBtnLstner(this),
    toNextBtnLstner(this),
    mergeBtnLstner(this),
    unMergeBtnLstner(this)
    {
    topMargins = 13;

    SimpleButton& toTopBtn = addButton(1, L"res\\to_top.png");
    toTopBtn.addListener(MouseEvent::PressType, &toTopBtnLstner);

    SimpleButton& toBottomBtn = addButton(2, L"res\\to_bottom.png");
    toBottomBtn.addListener(MouseEvent::PressType, &toBottomBtnLstner);

    SimpleButton& toUpBtn = addButton(3, L"res\\to_up.png");
    toUpBtn.addListener(MouseEvent::PressType, &toUpBtnLstner);

    SimpleButton& toNextBtn = addButton(4, L"res\\to_next.png");
    toNextBtn.addListener(MouseEvent::PressType, &toNextBtnLstner);

    SimpleButton& mergeBtn = addButton(5, L"res\\merge.png");
    mergeBtn.addListener(MouseEvent::PressType, &mergeBtnLstner);

    SimpleButton& unmergeBtn = addButton(6, L"res\\unmerge.png");
    unmergeBtn.addListener(MouseEvent::PressType, &unMergeBtnLstner);

    //setMouseEventMode(Ed::MEventMode_Top);
//    setMouseEventMode(Ed::MEventMode_Manual, &mergeBtn);
  }

  ControlLayer::~ControlLayer() {
    hash_map<int, SimpleButton*>::iterator it = buttons.begin();
    for(; it != buttons.end(); it++) {
      delete it->second;
    }
  }

  SimpleButton& ControlLayer::addButton(int id, const wchar_t* filename) {
    real x, y;
    if(buttons.size()%2==0){
      //topMargins+buttons.size()*27+3, 3
      x = 3;
      y = topMargins+buttons.size()/2*27+3;
    }else{
      x = 30;
      y = topMargins+buttons.size()/2*27+3;
    }
    SimpleButton* button = new SimpleButton(filename, x, y);
     addElement(button);
     buttons[id] = button;
     return *button;
   }

  void ControlLayer::mouseEnterEvent(const MouseEvent* e){
    cout<<"ControlLayer::mouseEnterEvent"<<endl;
  }
  void ControlLayer::mouseLeaveEvent(const MouseEvent* e){
    cout<<"ControlLayer::mouseLeaveEvent"<<endl;
  }

//  void ControlLayer::mouseMoveEvent(const MouseEvent* e){
//
//  }
}
